package com.pay.game.central.web.controller;

import com.alibaba.fastjson.JSON;
import com.pay.game.central.common.Result;
import com.pay.game.central.common.ResultGenerator;
import com.pay.game.central.security.annotaion.UserLoginToken;
import com.pay.game.central.web.service.DirectoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/directory")
public class DirectoryController {

    @Autowired
    private DirectoryService mDirectoryService;

    @UserLoginToken
    @GetMapping("/threshold")
    @ResponseBody
    Result<String> getThreshold(){
        return ResultGenerator.genSuccessResult(mDirectoryService.getThreshold()+"");
    }

    @UserLoginToken
    @PostMapping("/threshold")
    @ResponseBody
    Result<String> setThreshold(@RequestBody String body){
        mDirectoryService.setThreshold(JSON.parseObject(body).getInteger("threshold"));
        return ResultGenerator.genSuccessResult("操作成功");
    }

    @UserLoginToken
    @GetMapping("/storeOrderLimitDefault")
    @ResponseBody
    Result<String> getStoreOrderLimitDefault(){
        return ResultGenerator.genSuccessResult(mDirectoryService.getStoreOrderLimitDefault()+"");
    }

    @UserLoginToken
    @PostMapping("/storeOrderLimitDefault")
    @ResponseBody
    Result<String> setStoreOrderLimitDefault(@RequestBody String body){
        mDirectoryService.setStoreOrderLimitDefault(JSON.parseObject(body).getInteger("storeOrderLimitDefault"));
        return ResultGenerator.genSuccessResult("操作成功");
    }

    @UserLoginToken
    @GetMapping("/goodsTimeInterval")
    @ResponseBody
    Result<String> getGoodsTimeInterval(){
        return ResultGenerator.genSuccessResult(mDirectoryService.getGoodsTimeInterval()+"");
    }

    @UserLoginToken
    @PostMapping("/goodsTimeInterval")
    @ResponseBody
    Result<String> setGoodsTimeInterval(@RequestBody String body){
        mDirectoryService.setGoodsTimeInterval(JSON.parseObject(body).getInteger("goodsTimeInterval"));
        return ResultGenerator.genSuccessResult("操作成功");
    }

    @UserLoginToken
    @GetMapping("/runRangeLt")
    @ResponseBody
    Result<String> getRunRangeLt(){
        return ResultGenerator.genSuccessResult(mDirectoryService.getRunRangeLt() + "");
    }

    @UserLoginToken
    @PostMapping("/runRangeLt")
    @ResponseBody
    Result<String> setRunRangeLt(@RequestBody String body){
        mDirectoryService.setRunRangeLt(JSON.parseObject(body).getInteger("runRangeLt"));
        return ResultGenerator.genSuccessResult("操作成功");
    }

    @UserLoginToken
    @GetMapping("/orderTimeout")
    @ResponseBody
    Result<String> getOrderTimeout(){
        return ResultGenerator.genSuccessResult(mDirectoryService.getOrderTimeout() + "");
    }

    @UserLoginToken
    @PostMapping("/orderTimeout")
    @ResponseBody
    Result<String> setOrderTimeout(@RequestBody String body){
        mDirectoryService.setOrderTimeout(JSON.parseObject(body).getInteger("orderTimeout"));
        return ResultGenerator.genSuccessResult("操作成功");
    }


}
